/**
 * Created by lzz on 6/12/17.
 */
var t = getCookie("token");
$.ajax({
    url: BASE_URL + '/api/account/list/?token=' + t,
    type: "GET",
    dataType: "json",
    success: function (data) {
        var str = ""
        var delets = ''

        for (var i = 0; i < data.data.length; i++) {
            str += "<tr><td>" + data.data[i].id + "</td><td>" + data.data[i].name + "</td><td><button type='button' onclick='deletes(" + data.data[i].id + ")'>删除</button></td></tr>"
            $('#wx-main-content').html(str)
        }
    }
})
$('.btn').click(function () {
    var adds = $('#adds')
    if ($('.txt').val() === '') {
        alert('不能为空');
    } else {
        $.get(BASE_URL + "/api/account/post/?token=" + t + "&" + adds.serialize(), function (msg) {
                console.log(msg.code)
                if (msg.code == 0) {
                    alert('添加成功!');
                    location.reload();
                }
                else {
                    console.log(msg.data.id)
                }
            }
        )
    }
})
function deletes(id) {
    $.get(BASE_URL + "/api/account/del/?token=" + t + "&id=" + id, function (msg) {
        if (msg.code == 0) {
            alert('删除成功!');
            location.reload();
        }
    })
}